package com.blic.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blic.entity.UserInfoEntity;
import com.blic.mapper.UserInfoMapper;
import com.blic.service.AbstractService;
import com.blic.service.api.IUserInfoService;
import com.blic.utils.ExampleUtil;
import com.blic.utils.MyMapper;

import tk.mybatis.mapper.entity.Example;
 

@Service
public class UserInfoServiceImpl extends AbstractService implements IUserInfoService {
	
	
    @Autowired
    protected UserInfoMapper userInfoMapper;
    
    @Override
    public long insert(UserInfoEntity bean) {
        Number num = userInfoMapper.insertSelective(bean);
        return num.longValue();
    }

    @Override
    public boolean update(UserInfoEntity bean) {
        int result = userInfoMapper.updateByPrimaryKey(bean);
        boolean bool = true;
        if (result != 1) {
            bool = false;
        }
        return bool;
    }

    @Override
    public boolean removeById(long id) {
        int result = 0;
        result = this.userInfoMapper.deleteByPrimaryKey(id);
        boolean bool = true;
        if (result != 1) {
            bool = false;
        }
        return bool;
    }


    @Override
    public List<UserInfoEntity> queryAll() {
        return this.userInfoMapper.selectAll();
    }

	@Override
	public  List<UserInfoEntity> queryList(UserInfoEntity entity) {
		Example example;
		try {
			example = ExampleUtil.getExampleUseAndLike(UserInfoEntity.class, entity);
			return this.userInfoMapper.selectByExample(example);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public UserInfoEntity queryByOpenId(String openId) {
		Example example = null;
		example = new Example(UserInfoEntity.class);
		example.clear();
		example.createCriteria().andEqualTo("openId", openId);
		List<UserInfoEntity> results = userInfoMapper.selectByExample(example);
		if(results.size()>0)
			return results.get(0);
		return null;
	}
 
    
   
}
